/**
 * ClockManager
 *
 * Provides the ability:
 * 1. Use a timer to get the seconds between a start/stop point
 * 2. Create a countdown which:
 *    a. triggers a mutex event if requested
 *    b. can be checked later to see if the countdown finished
 *
 * Todo: Monitor thread may not be thread-safe, should use a mutex before & after performing check.
 */
#ifndef _ClockManager
#define _ClockManager

#include <Windows.h>

struct Clock {
	bool isStopwatch;
	bool isCountdown;

	char *name;
	time_t tStart, tStop;	// time started, time stopped
	time_t sStart, sCurr;	// seconds to start countdown with, seconds left in the countdown
	HANDLE trigger;		// occurs when countdown completes
	Clock *prev, *next;
};

class ClockManager {
private:
	// start & stop the monitor thread which watches for countdowns to finish
	void monitorStart();
	void monitorStop();

public:
	Clock *head;

	unsigned mId;
	bool mStop;
	HANDLE mHandle;

	// Constructor
	ClockManager();
	// Deconstructor
	~ClockManager();

	// add item to manage
	bool addStopwatch(char* /*name*/);
	bool addCountdown(char* /*name*/, int /*seconds*/, HANDLE /*mutex*/);

	// del managed item
	bool delStopwatch(char* /*name*/);
	bool delCountdown(char* /*name*/);

	bool start(char* /*name*/);	// stopwatch = record start time,	countdown = start/continue countdown
	bool stop(char* /*name*/);	// stopwatch = record stop time,	countdown = pause countdown
	bool reset(char* /*name*/);	// stopwatch = nothing,				countdown = reset back to start
	bool isComplete(char* /*name*/);	// stopwatch = nothing,		countdown = whether countdown is complete

	time_t getStart(char* /*name*/);	// stopwatch = start time		countdown = start time
	time_t getStop(char* /*name*/);	// stopwatch = stop time		countdown = finish time
	time_t getDuration(char* /*name*/);// stopwatch = stop - start		countdown = seconds since complete
};

#endif // _ClockManager